package com.woniuxy.threadpool;

import lombok.extern.slf4j.Slf4j;


import java.util.concurrent.SynchronousQueue;
import static com.woniuxy.untis.Sleep.sleep;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 固定大小线程池
 * <P> Date: 2022/4/10:16:31
 * <P> Description:
 */
@Slf4j(topic = "c.ThreadPoolTest02")
@SuppressWarnings("all")
public class ThreadPoolTest03 {
    public static void main(String[] args) {
        SynchronousQueue<Integer> integers = new SynchronousQueue<>();
        new Thread(() -> {
            try {
                log.debug("putting {} ", 1);
                integers.put(1);
                log.debug("{} putted...", 1);

                log.debug("putting...{} ", 2);
                integers.put(2);
                log.debug("{} putted...", 2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t1").start();

        sleep(1000);

        new Thread(() -> {
            try {
                log.debug("taking {}", 1);
                integers.take();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t2").start();

        sleep(1000);

        new Thread(() -> {
            try {
                log.debug("taking {}", 2);
                integers.take();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t3").start();
    }
}
